#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 100005;
bool cmp(int a, int b)
{
    return a > b;
}
int main()
{
    int n, m, i, cp[maxn] = {0}, pv[maxn] = {0}, total = 0;
    cin >> n;
    for (i = 0; i < n; i++)
        scanf("%d", &cp[i]);
    cin >> m;
    for (i = 0; i < m; i++)
        scanf("%d", &pv[i]);
    sort(cp, cp + n, cmp);
    sort(pv, pv + m, cmp);
    for (i = 0; i < m; i++)
    {
        if (cp[i] > 0 && pv[i] > 0)
            total += cp[i] * pv[i];
        else
            break;
    }
    sort(cp, cp + n);
    sort(pv, pv + m);
    for (i = 0; i < m; i++)
    {
        if (cp[i] < 0 && pv[i] < 0)
            total += cp[i] * pv[i];
        else
            break;
    }
    cout << total << endl;
    return 0;
}